<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Document</title>
  <style>
    * {
      padding: 0;
      margin: 0
    }

    label {
      width: 80px;
      display: inline-block;
      margin-bottom: 10px;
    }
  </style>
</head>

<body>
  <%= title%>
    <form id="form" action="/api/useRegister" method="POST">
      <label for="usename">用户名</label>
      <input id="usename" name="username" type="text" placeholder="请输入用户名">
      <br>
      <label for="psd">密 码</label>
      <input id="psd" name="password" type="text" placeholder="请输入密码">
      <br>
      <label for="psd1">确认密码</label>
      <input id="psd1" type="text" placeholder="请确认密码">
      <br>

      <a href="javascript:;" id="btn">注册</a>
    </form>

</body>

</html>
<script src="/javascripts/jquery-1.11.1.min.js"></script>
<script>
  $('#btn').click(function () {
    if ($('#usename').val() == '') {
      alert('用户名不能为空')
    } else if ($('#psd').val() == '') {
      alert('密码不能为空')
    } else if ($('#psd').val() !== $('#psd1').val()) {
      alert('两次密码输入不一致')
    } else {
      // $('#form').submit();
      $.ajax({
        url: '/api/useRegister',
        type: 'post',
        data: {
          username: $('#usename').val(),
          password: $('#psd').val()
        },
        dataType: 'json',
        success: function (data) {
          if (data.code == 0) {
            alert(data.msg)
          }
        }
      })
    }

  })
</script>